<?php
    session_start();
    include('top.php');
    include('../sql.php');
    $web_info = "select * from webinfo";
    $web_info_result = $link->query($web_info);
    $web_info_row = mysqli_fetch_array($web_info_result);
?>
<div class="home-container-body">
    <?php include('nav.php'); ?>
</div>

<div class="admin_hone-content">
    <form id="infoForm">
        <table width="100%">
            <tr>
                <td>网站名称</td>
                <td><input type="text" name="webname" value="<?php echo $web_info_row['webname']; ?>"></td>
            </tr>
            <tr>
                <td>联系电话</td>
                <td><input type="text" name="tel" value="<?php echo $web_info_row['tel']; ?>"></td>
            </tr>
            <tr>
                <td>联系邮箱</td>
                <td><input type="text" name="mail" value="<?php echo $web_info_row['mail']; ?>"></td>
            </tr>
            <tr>
                <td>联系地址</td>
                <td><input type="text" name="address" value="<?php echo $web_info_row['address']; ?>"></td>
            </tr>
            <tr>
                <td>ICP备案号</td>
                <td><input type="text" name="icp" value="<?php echo $web_info_row['icp']; ?>"></td>
            </tr>
            <tr>
                <td>首页图片</td>
                <td><input type="text" name="banner" value="<?php echo $web_info_row['banner']; ?>"></td>
            </tr>
            <tr>
                <td>招生介绍</td>
                <td><textarea name="introduce" rows="20">招生对象可以是本科阶段就读于本校，在校表现良好且毕业时取得了主修专业毕业证书及学士学位证书；或者普通高校本科毕业并获得学士学位的2024年应届毕业生，以及近三年普通高校本科毕业并获得学士学位、目前未就业的往届生。为全日制普通高等教育2024年应届本科毕业生。</textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="submit" value="修改">
                    <?php if (empty($web_info_row['reg'])) { ?>
                    <a href="control.php?action=reg&int=1">开启注册</a>
                    <?php } else { ?>
                    <a href="control.php?action=reg&int=0">关闭注册</a>
                    <?php } ?>
                    <div id="sResult"></div>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript" src="../static/js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#infoForm').on('submit', function(e){
            e.preventDefault();
            var formData = $(this).serialize();

            $.ajax({
                url: 'control.php?action=webinfo',
                type: 'POST',
                data: formData,
                success: function(response){
                    $('#sResult').empty();
                    $('#sResult').html(response);
                    location.reload();
                },
                error: function(error){
                    console.log(error);
                    $('#sResult').html('失败，请稍后再试。');
                }
            });
        });
    });
</script>
<?php include('bottom.php'); ?>